//
//  ProgressImageView.swift
//  JLWeibo
//
//  Created by sunjinliang on 15/12/19.
//  Copyright © 2015年 sunjinliang. All rights reserved.
//

import UIKit

class ProgressImageView: UIImageView {
   lazy var progressView : ProgressView = ProgressView()
    var progress : CGFloat = 0{
        didSet{
            progressView.progress = progress
        }
    }
    init(){
        
        super.init(frame: CGRectZero)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
     func setupUI(){
        addSubview(progressView)
        progressView.backgroundColor = UIColor.clearColor()
        progressView.snp_makeConstraints { (make) -> Void in
            make.edges.equalTo(self.snp_edges)
        }
    }
   
}
class ProgressView: UIView {
    var progress : CGFloat = 0{
        didSet{
            setNeedsDisplay()
        }
    }
    
    override func drawRect(rect: CGRect) {
        let center = CGPointMake(rect.width * 0.5, rect.height * 0.5)
        let radius = min(rect.height, rect.width) * 0.5
        let startAngle = -CGFloat(M_PI_2)
        let endAngle = startAngle + progress * 2 * CGFloat(M_PI)
        let path = UIBezierPath(arcCenter: center, radius: radius, startAngle: startAngle, endAngle: endAngle, clockwise: true)
        path.addLineToPoint(center)
        path.closePath()
        UIColor(white: 1.0, alpha: 0.5).setFill()
        path.fill()
        
        
    }


}